import Taro from "@tarojs/taro";
import globalData from "@/libs/globalData";
import { getGrades, getCities } from "_api/base-api";
import { userInfo } from "_api/mine";

export default {
  init() {
    Taro.getSystemInfo({
      success: res => {
        globalData.setData("navHeight", res.statusBarHeight);
        globalData.setData("windowHeight", res.windowHeight);
      }
    });
    const { height, top } = Taro.getMenuButtonBoundingClientRect();
    globalData.setData("MBHeight", height);
    globalData.setData("MBTop", top);
    this.setGrades();
    this.setCities();
  },
  async setGrades() {
    let { data } = await getGrades();
    Taro.setStorageSync("gradesList", data);
    globalData.setData("gradesList", data);
  },
  async setCities() {
    let { data } = await getCities();
    Taro.setStorageSync("citiesList", data);
    globalData.setData("citiesList", data);
  },
  async setUser() {
    let { data } = await userInfo();
    let { grade_id, city_id } = data;
    Taro.setStorageSync("grade_id", grade_id);
    Taro.setStorageSync("city_id", city_id);
  }
};
